package cn.kiliter.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter("/*")
public class Filter implements javax.servlet.Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        //1.设置POST请求中文乱码的问题
        HttpServletResponse mResponse = (HttpServletResponse) response;
        mResponse.setHeader("content-type", "text/html;charset=utf-8");
        HttpServletRequest hsr = (HttpServletRequest)request;
        if(hsr.getMethod().equalsIgnoreCase("post")){
            request.setCharacterEncoding("UTF-8");
        }
            chain.doFilter(request, response);



    }




    public void init(FilterConfig config) throws ServletException {

    }

}
